package com.hb.trade.server.expert.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hb.core.pojo.expert.dto.ExpertMajorDTO;
import com.hb.core.pojo.expert.entity.ExpertMajor;
import com.hb.core.pojo.expert.mapper.ExpertMajorMapper;
import com.hb.trade.server.expert.service.ExpertMajorService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author jinhaolin
 * @date 2022/1/19 17:47
 **/
@Service
public class ExpertMajorServiceImpl extends ServiceImpl<ExpertMajorMapper, ExpertMajor> implements ExpertMajorService {
    @Override
    public List<ExpertMajorDTO> majorList(ExpertMajorDTO expertMajorDTO) {

        String parentMajorCode = null;
        if (expertMajorDTO != null && StrUtil.isNotEmpty(expertMajorDTO.getParentCode())) {
            parentMajorCode = expertMajorDTO.getParentCode();
        }

        List<ExpertMajorDTO> expertMajors = baseMapper.majorList(parentMajorCode, expertMajorDTO.getOrgId());
        return expertMajors;
    }

    @Override
    public ExpertMajorDTO findByMajorCode(String majorCode) {
        QueryWrapper<ExpertMajor> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ExpertMajor::getMajorCode, majorCode);
        ExpertMajor expertMajor = this.getOne(queryWrapper);
        return expertMajor.to(ExpertMajorDTO.class);
    }
}
